<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script>
			let obj = {
				id: 1,
				pname: '小米',
				price: 3999,
			};
			// 1. 以前的添加和修改方式
			// obj.num = 10000;
			// obj.price = 999;
			// 2. Object.defineProperty() 定义对象中新属性或修改原有的属性
			Object.defineProperty(obj, 'price', {
				value: 1999,
			});
			console.log(obj);

			Object.defineProperty(obj, 'num', {
				value: 10000,
			});
			console.log(obj);

			Object.defineProperty(obj, 'id', {
				// 不允许修改 id 值
				writable: false,
			});
			obj.id = 2;
			console.log(obj);

			Object.defineProperty(obj, 'address', {
				value: '60栋531',
				writable: false,
				enumerable: false,
				configurable: false, // 不可删除，不可修改
			});
			console.log(obj);
			console.log(Object.keys(obj));
			delete obj.address;
			console.log(obj);
		</script>
	</body>
</html>
